﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

using MT.eVotePRS.Model;
using MT.eVotePRS.Presentation;
using MT.eVotePRS.Presentation.Presenter;

namespace MT.eVotePRS.UI.UserControls
{
    public partial class RptIndividual : UserControl, IViewRptIndividual
    {
        #region IViewRptIndividual

        IndividualReport _report;
        string _handsetId;
        string _studentId;

        public IndividualReport Report { get { return _report; } }
        public string HandsetId
        {
            set
            {
                _handsetId = value;
                txtHandsetID.Text = _handsetId;
            }
            get { return _handsetId; }
        }

        public string StudentId 
        {
            set
            {
                _studentId = value;
                txtStudentID.Text = _studentId;
            }
            get { return _studentId; }
        }

        public event EventHandler GenerateReport;

        #endregion

        #region INotifyPropertyChanged Members
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        public RptIndividual()
        {
            InitializeComponent();
            txtHandsetID.KeyDown += OnKeyDown;
            txtStudentID.KeyDown += OnKeyDown;

            this.rbtHandsetID.CheckedChanged += OnCheckedChanged;
            this.rbtStudentID.CheckedChanged += OnCheckedChanged;

            rbtHandsetID.Checked = true;
        }

        void OnKeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (string.IsNullOrEmpty(txtHandsetID.Text))
                {
                    RaiseGenerateReport();
                }
            }
        }

        void OnCheckedChanged(object sender, EventArgs e)
        {
            //if ((RadioButton)sender == rbtHandsetID) { }
            //else if ((RadioButton)sender == rbtStudentID) { }

            if (rbtHandsetID.Checked)
                this._report = IndividualReport.Handset;
            else if (rbtStudentID.Checked)
                this._report = IndividualReport.Student;
        }

        protected virtual void RaiseGenerateReport()
        {
            EventHandler handlers = GenerateReport;
            if (handlers != null)
            {
                handlers(this, EventArgs.Empty);
            }
        }

        protected virtual void RaisePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handlers = PropertyChanged;
            if (handlers != null)
            {
                handlers(this, new PropertyChangedEventArgs(propertyName));
            }
        }

    }
}
